﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace SomeGame.GUI.WidgetActions {

    public class WidgetActionProcessor {

        public readonly IList<WidgetAction> WidgetActions = new List<WidgetAction>();
        public bool IsActive;

        public void Update(GameTime gameTime) {
            IsActive = false;
            for (int i = WidgetActions.Count-1; i >= 0; i--) {
                WidgetAction widgetAction = WidgetActions[i];
                switch (widgetAction.State) {
                    case WidgetActionState.Ready:
                        widgetAction.State = WidgetActionState.Running;
                        break;
                    case WidgetActionState.Running:
                        widgetAction.Update(gameTime);
                        if (!IsActive) {
                            IsActive = true;
                        }
                        break;
                    case WidgetActionState.Done:
                        WidgetActions.Remove(widgetAction);
                        break;
                }
            }
        }

    }

}